# Based on:
# plymouth: https://abf.io/import/rosa-theme
# grub2: https://abf.io/import/grub2-theme-rosa

# grub does not exist on e2k
%ifnarch %{e2k}
%bcond_without grub
%else
%bcond_with grub
%endif

# cannot make "BuildArch: noarch" because of %%ifnarch
%define debug_package %{nil}

Summary(ru_RU.UTF-8):	Темы grub2 и plymouth для МОС
Summary:	Grub2 and Plymouth themes for MOS
Name:		branding-mos-school
License:	GPL
Group:		System/Base
Version:	12
Release:	2
Url:		https://hub.mos.ru/mos/pkgs/%{name}
Vendor:		MOS
Source0:	README.md

# grub2_ prefix
Source101:	grub2_boot.png
Source102:	grub2_scrollbar_border_c.png
Source103:	grub2_scrollbar_border_n.png
Source104:	grub2_scrollbar_border_s.png
Source105:	grub2_scrollbar_slider_c.png
Source106:	grub2_scrollbar_slider_n.png
Source107:	grub2_scrollbar_slider_s.png
Source108:	grub2_selected_blob_c.png
Source109:	grub2_tick.png
Source110:	grub2_zero.png

Source111:	grub2_theme.txt

# plymouth_ prefix
Source201:	plymouth_boot16x9.png
Source202:	plymouth_boot4x3.png
Source203:	plymouth_box.png
Source204:	plymouth_bullet.png
Source205:	plymouth_entry.png
Source206:	plymouth_lock.png
Source207:	plymouth_progress_bar.png
Source208:	plymouth_progress_box.png
Source209:	plymouth_shutdown16x9.png
Source210:	plymouth_shutdown4x3.png

Source211:	plymouth_mos.plymouth
Source212:	plymouth_mos.script


BuildRequires:	fonts-ttf-dejavu
BuildRequires:	%{_bindir}/convert
%if %{with grub}
BuildRequires:	%{_bindir}/grub2-mkfont
%endif

%description
Grub2 and Plymouth themes for MOS.

%description -l ru_RU.UTF-8
Оформление МОС для экранов grub2 и plymouth.
#--------------------------------------------------------

%if %{with grub}

%package grub2
Summary(ru_RU.UTF-8):	Тема grub2 для МОС
Summary:	Grub2 theme for MOS
Requires:	grub2
Recommends:	(anaconda-%{name}-grub2 if anaconda-core)
# required by grub2
Provides:	grub2-theme = %{EVRD}

%description grub2
Grub2 theme for MOS.

%description -l ru_RU.UTF-8 grub2
Оформление экрана grub2 для МОС.

%files grub2
/boot/grub2/themes/mos

%posttrans grub2
# copied from grub2-theme-rosa.spec
if [ $1 -eq 1 ] ; then
# Remove all previous theme from config
sed -i '/GRUB_THEME=*/d' %{_sysconfdir}/default/grub
sed -i '/GRUB_BACKGROUND=*/d' %{_sysconfdir}/default/grub
# Remove trailing blank lines from /etc/default/grub
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' %{_sysconfdir}/default/grub
# Check that /etc/default/grub ends in a linefeed
[ "$(tail -n 1 %{_sysconfdir}/default/grub | wc --lines)" = "1" ] || echo >> %{_sysconfdir}/default/grub
# Add theme
echo "GRUB_THEME=\"/boot/grub2/themes/mos/theme.txt\"" >> %{_sysconfdir}/default/grub
#echo "GRUB_BACKGROUND=\"/boot/grub2/themes/mos/terminal_background.png\"" >> %{_sysconfdir}/default/grub
# Regenerate configure on install or update
# Do not fail in chroots etc.
%{_sbindir}/update-grub2 || :
fi

%postun
# Only if uninstalling theme
if [ $1 -eq 0 ]; then
# Remove theme from config
sed -i '/GRUB_THEME=\/boot\/grub2\/themes\/mos\/theme.txt/d' %{_sysconfdir}/default/grub
fi

#--------------------------------------------------------

%package -n anaconda-%{name}-grub2
Summary(ru_RU.UTF-8):	Окружение для livecd-tools с темой ОС для grub2
Summary:	Workaround to make livecd-tools use MOS Grub theme
Conflicts:	grub2-theme-rosa

%description -n anaconda-%{name}-grub2
%{summary}
livecd-tools copies /boot/grub2/themes/rosa/*,
Anaconda removes all anaconda-* packages after installing system.
This package makes rosa directory be available at ISO build time.

%description -l ru_RU.UTF-8 -n anaconda-%{name}-grub2
Окружение для livecd-tools с темой ОС для grub2.
livecd-tools копируется в /boot/grub2/themes/rosa/*,
Anaconda удаляет все пакеты по шаблону anaconda-* после установки системы.
Этот пакет делает доступной директорию rosa во вемя сборки ISO образа.

%files -n anaconda-%{name}-grub2
/boot/grub2/themes/rosa

#--------------------------------------------------------
%endif

%package plymouth
Summary(ru_RU.UTF-8):	Тема plymouth для МОС
Summary:	Plymouth theme for MOS
Requires:	plymouth
Requires:	plymouth-plugin-script
Requires:	rosa-kernel-tools
Requires(post,postun):	plymouth-scripts
# run our %%post after Rosa-theme-EE if it is also being installed
OrderWithRequires(post):	Rosa-theme-EE

%description plymouth
Plymouth theme for MOS.

%description -l ru_RU.UTF-8 plymouth
Оформление plymouth для МОС.

%files plymouth
/var/spool/initramfs-regen/%{name}-plymouth
%{_datadir}/plymouth/themes/mos

%post plymouth
plymouth-set-default-theme mos

%postun plymouth
if [ $1 -lt 1 ]; then
    plymouth-set-default-theme --reset
fi

#--------------------------------------------------------

%prep
%setup -T -c
cp %sources .

%install
# empty file for rosa-kernel-tools
mkdir -p %{buildroot}/var/spool/initramfs-regen
touch %{buildroot}/var/spool/initramfs-regen/%{name}-plymouth

# Plymouth theme
mkdir -p %{buildroot}%{_datadir}/plymouth/themes/mos
for i in plymouth_*
do
	cp -v "$i" "%{buildroot}%{_datadir}/plymouth/themes/mos/${i#plymouth_}"
done

# Grub2 theme
%if %{with grub}
mkdir -p %{buildroot}/boot/grub2/themes/mos
grub2-mkfont -v -s 12 -o %{buildroot}/boot/grub2/themes/mos/dejavu_sans_mono_12.pf2 /usr/share/fonts/TTF/dejavu/DejaVuSansMono.ttf
grub2-mkfont -v -s 10 -o %{buildroot}/boot/grub2/themes/mos/dejavu_sans_10.pf2 /usr/share/fonts/TTF/dejavu/DejaVuSans.ttf
grub2-mkfont -v -s 12 -o %{buildroot}/boot/grub2/themes/mos/dejavu_sans_12.pf2 /usr/share/fonts/TTF/dejavu/DejaVuSans.ttf
grub2-mkfont -v -s 14 -o %{buildroot}/boot/grub2/themes/mos/dejavu_sans_bold_14.pf2 /usr/share/fonts/TTF/dejavu/DejaVuSans-Bold.ttf
for i in grub2_*
do
	cp -v "$i" "%{buildroot}/boot/grub2/themes/mos/${i#grub2_}"
done
cp -r %{buildroot}/boot/grub2/themes/{mos,rosa}
%endif
